import axios from 'axios'
import Vue from 'vue'

const qs = require('qs');

const Url = "/Cyberspace/main/";

const loading  = {
  show(){
    Vue.$vux.loading.show({
      text: '加载中...'
    });
  },
  hide(){
    Vue.$vux.loading.hide();
  }
};


export const requestWithLoading = (url, data, call) => {
  loading.show();
  axios.post(Url + url + ".do", qs.stringify(data),{timeout:20000})
    .then((res) => {
      loading.hide();
      call(res.data);
    })
    .catch(function (err) {
      loading.hide();
      if (err.error) {
        alert("服务器没有响应，请稍后重试");
      }
    })
};

export const requestNoLoading = (url, data, call) => {
  axios.post(Url + url + ".do", qs.stringify(data))
    .then((res) => {
      call(res.data);
    })
    .catch(function (err) {
      if (err.error) {
        alert("服务器没有响应，请稍后重试");
      }
    })
};
